home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / lib / Point.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  2KB  |  103 lines

  1. /* Point.c  -- implementation of X-Y coordinates
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet: kgorlen@alw.nih.gov
  20.     August, 1985
  21.  
  22. Function:
  23.     
  24. A Point represents an x-y coordinate pair.  By convention, Point(0,0) is
  25. the top left corner of the display, with x increasing to the right and y
  26. increasing to the bottom.
  27.  
  28. $Log:    Point.c,v $
  29.  * Revision 3.0  90/05/20  00:20:45  kgorlen
  30.  * Release for 1st edition.
  31.  * 
  32. */
  33.  
  34. #include "Point.h"
  35. #include "nihclIO.h"
  36.  
  37. #define    THIS    Point
  38. #define    BASE    Object
  39. #define BASE_CLASSES BASE::desc()
  40. #define MEMBER_CLASSES
  41. #define VIRTUAL_BASE_CLASSES Object::desc()
  42.  
  43. DEFINE_CLASS(Point,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Point.c,v 3.0 90/05/20 00:20:45 kgorlen Rel $",NULL,NULL);
  44.  
  45. Point Point::max(const Point& p) const
  46. {
  47.     return Point(MAX(xc,p.xc),MAX(yc,p.yc));
  48. }
  49.  
  50. Point Point::min(const Point& p) const
  51. {
  52.     return Point(MIN(xc,p.xc),MIN(yc,p.yc));
  53. }
  54.  
  55. bool Point::isEqual(const Object& ob) const
  56. {
  57.     return ob.isSpecies(classDesc) && *this==castdown(ob);
  58. }
  59.  
  60. const Class* Point::species() const    { return &classDesc; }
  61.  
  62. unsigned Point::hash() const    { return xc^yc; }
  63.  
  64. int Point::compare(const Object& ob) const
  65. {
  66.     assertArgSpecies(ob,classDesc,"compare");
  67.     const Point& p = castdown(ob);
  68.     int t = yc - p.yc;;
  69.     if (t != 0) return t;
  70.     else return xc - p.xc;
  71. }
  72.  
  73. void Point::deepenShallowCopy()    {}
  74.  
  75. void Point::printOn(ostream& strm) const
  76. {
  77.     strm << '(' << xc << ',' << yc << ')';
  78. }
  79.  
  80. Point::Point(OIOin& strm)
  81.     : BASE(strm)
  82. {
  83.     strm >> xc >> yc;
  84. }
  85.  
  86. void Point::storer(OIOout& strm) const
  87. {
  88.     BASE::storer(strm);
  89.     strm << xc << yc;
  90. }
  91.  
  92. Point::Point(OIOifd& fd)
  93.     : BASE(fd)
  94. {
  95.     fd >> xc >> yc;
  96. }
  97.  
  98. void Point::storer(OIOofd& fd) const
  99. {
  100.     BASE::storer(fd);
  101.     fd << xc << yc;
  102. }
  103.